﻿using PMS.Domain.Exceptions;
using PMS.Domain.Seedwork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PMS.Domain.AggregatesModel.ProjectAggregate
{

    /// <summary>
    /// 审核类型
    /// </summary>
    public class ProjectAuditStatus: Enumeration
    {
        public static ProjectAuditStatus Approving = new ProjectAuditStatus(1, "待审核");
        public static ProjectAuditStatus Agree = new ProjectAuditStatus(2, "同意");
        public static ProjectAuditStatus Refuse = new ProjectAuditStatus(3, "拒绝");
   
        protected ProjectAuditStatus()
        {
        }

        public ProjectAuditStatus(int id, string name)
            : base(id, name)
        {
        }

        public static IEnumerable<ProjectAuditStatus> List() =>
            new[] { Approving,Agree,Refuse};

        /// <summary>
        /// 根据名称获取 审核类型
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ProjectAuditStatus FromName(string name)
        {
            var state = List()
                .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));

            if (state == null)
            {
                throw new PMSDomainException($"数据不存在，可用审核类型有: {String.Join(",", List().Select(s => s.Name))}");
            }

            return state;
        }

        /// <summary>
        /// 根据ID 获取审核状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ProjectAuditStatus From(int id)
        {
            var state = List().SingleOrDefault(s => s.Id == id);

            if (state == null)
            {
                throw new PMSDomainException($"数据不存在，可用审核类型有: {String.Join(",", List().Select(s => s.Name))}");
            }

            return state;
        }


    }
}
